﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace HRDexCapstoneProject.Functions.JobPosting
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void txtSubmit_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=(local); Initial Catalog=HRdexDB; Integrated Security=SSPI");
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();

            conn.Open();

            SqlCommand cmd = new SqlCommand("Insert Into catJobTitle (Title, Description, Salary, Skills, DatePosted, JobType, Attachment) Values (@title, @desc, @salary, @skills, @pubDate, @jobType, @attachment)", conn);
            Stream fs = fuAttachment.PostedFile.InputStream;
            BinaryReader br = new BinaryReader(fs);
            Byte[] bytes = br.ReadBytes((Int32)fs.Length);

            cmd.Parameters.Add("@title", SqlDbType.VarChar).Value = txtPosition.Text;
            cmd.Parameters.Add("@desc", SqlDbType.VarChar).Value = txtDescription.Text;
            cmd.Parameters.Add("@salary", SqlDbType.VarChar).Value = txtSalary.Text;
            cmd.Parameters.Add("@skills", SqlDbType.VarChar).Value = txtSkill.Text;
            cmd.Parameters.Add("@pubDate", SqlDbType.DateTime).Value = DateTime.Now;
            cmd.Parameters.Add("@jobType", SqlDbType.VarChar).Value = txtJobType0.Text;
            cmd.Parameters.Add("@attachment", SqlDbType.Binary).Value = bytes;

            cmd.ExecuteNonQuery();

            conn.Close();
        }
    }
}